<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Search_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

    public function count_search_find($key=array())
    {
        $this->db->select('good_id');
        $this->db->from('shop_goods');
        if($key){
            $this->db->group_start();
            foreach($key as $k => $v){
                $this->db->or_like('good_title', $v);
            }
            $this->db->group_end();
        }
        $this->db->where('good_lock',0);
        $total=$this->db->count_all_results();
        return $total;  
    }

    public function search_find($page, $limit, $key=array())
    {
        $start = $page*$limit;
        $this->db->select('*');
        $this->db->from('shop_goods');
        if($key){
            $this->db->group_start();
            foreach($key as $k => $v){
                $this->db->or_like('good_title', $v);
            }
            $this->db->group_end();
        }       
        $this->db->where('good_lock',0);
        $this->db->order_by('good_add_time','desc');
        $this->db->limit($limit,$start);
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }

    /** 按照频道查询次数排序
     * @return mixed
     */
    public function get_hot_categorys($limit=5,$user_id=0){
        if($user_id){
            $this->db->select('category_id, fox_category.category_name,fox_category.id');
            $this->db->from('fox_user_categorys');
            $this->db->join('fox_category','fox_user_categorys.category_tid = fox_category.id','left');
            $this->db->where('user_id',$user_id);
            $this->db->order_by('catogory_view','asc');
            $this->db->limit($limit);
            $query = $this->db->get();
            if($query->num_rows() > 0){
                return $query->result_array();
            }
        }
    }


}
